/***************************************************************************
 *   Copyright (C) 2007 by Fernando Pacheco,,,   *
 *   fernando.pacheco@ingesur.com.uy   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef PIPER_H
#define PIPER_H

#include <iostream>
#include <vector>

#include "piperdata.h"
#include "piperpoint.h"
#include "point.h"
#include "line.h"

/**
 * @class Piper
 * This class reside in the libhidrogeo library, has no dependencies with Qt or Miih and do everything related to Piper diagrams.
 * @brief This class do everything related to Piper diagrams
 * @author Fernando Pacheco <fernando_dot_pacheco_at_ingesur_dot_com_dot_uy>
 *
*/

typedef PiperData Data;
typedef std::vector<Data> VData;

class HIDROGEO_EXPORT Piper {

  public:
    Piper(double theWidth = 2000.0, double theHeight = 2000.0);
    ~Piper();
    /// Set the width of the device
    void setWidth(double theValue);
    /// Set the height of the device
    void setHeight(double theValue);
    /// Set the margin of the device
    void setMargin(double theMargins() );
    /// Set the extra margin of the device
    void setEMargin(double theEMargins());
    /// Set the triangles separation
    void setTSepar(double theValue);
    /// Get lenght of the device
    double height();
    /// Get width of the device
    double width();
    /// Get triangle lenght
    double tLenght();
    /// Get triangle height
    double tHeight();
    /// Get triangle separation
    double tSepar();
    /// Set the data for the diagram
    void setData(VData theData);
    /// Get the data for the diagram
    VData data();
    /// Get the vertices of the left triangle (lr,ll,t)
    std::vector<Point> tLVertice();
    /// Get the vertices of the right triangle (ll,lr,t)
    std::vector<Point> tRVertice();
    /// Get the vertices of the rombo (l,r,t,b)
    std::vector<Point> rVertice();
    /// Get the point of LTriangle for this data
    Point lTDataPoint(PData theCData);
    /// Get the point of RTriangle for this data
    Point rTDataPoint(PData theAData);
    /// Get the point of Rombo for this data
    Point rDataPoint(const Point left,const Point right);
    /// Get all the point for the data
    std::vector<PiperPoint> dataPoint();
    /**
    * Get all the points of the grid of the left triangle
    * @param rL double betwen 0 and 1 (Default=0.1). Lower axis.
    * @param lT double betwen 0 and 1 (Default=0.1). Left axis.
    * @param tR double betwen 0 and 1 (Default=0.1). Right axis.
    * @return vector of Lines for this triangle
    */
    std::vector<Line> lTGrid(double rL=0.1,double lT=0.1,double tR=0.1);
    /**
    * Get all the points of the grid of the right triangle
    * @param lR double betwen 0 and 1 (Default=0.1). Lower axis.
    * @param rT double betwen 0 and 1 (Default=0.1). Right axis.
    * @param tL double betwen 0 and 1 (Default=0.1). Left axis.
    * @return vector of Lines for this triangle
    */
    std::vector<Line> rTGrid(double lR=0.1,double rT=0.1,double tL=0.1);
    /**
    * Get all the points of the grid of the rombo
    * @param l double betwen 0 and 1 (Default=0.1). Left axis.
    * @param r double betwen 0 and 1 (Default=0.1). Right axis.
    * @return vector of Lines for the rombo
    */
    std::vector<Line> rGrid(double l=0.1,double r=0.1);

  private:
    /// Set the lenght of the triangles
    void setTLength();
    /// Set the height of the triangles
    void setTHeight();
    /// Set the vertices for L triangle
    void setLTVertices();
    /// Set the vertices for R triangle
    void setRTVertices();
    /// Set the vertices for rombo
    void setRVertices();
    /// Set the vertices for L,R triangle and rombo
    void setVertices();

    /// Widht of the device
    double mWidth;
    /// Height of the device
    double mHeight;
    /// Margin L,R,T,B
    double mMargin[4];
    /// Extra margin L,R,T,B
    double mEMargin[4];
    /// lenght of the triangles
    double mTLenght;
    /// height of the triangles
    double mTHeight;
    /// separation betwen triangles
    double mTSepar;
    /// Vertices of the left triangle
    std::vector<Point> mTLVertice;
    /// Vertices of the right triangle
    std::vector<Point> mTRVertice;
    /// Vertices of the rombo
    std::vector<Point> mRVertice;
    /// Raw data
    VData mData;
    /// Coordinates of data
    //std::vector<Point> mDataPoint;
};

#endif
